import { CHANGE_ENTER_LOADING, CHANGE_CURRENT_ALBUM } from './constant'
import { getAlbumDetailRequest } from '../../../api/request'
import { fromJS } from 'immutable'

const changeCurrentAlbum = data => ({
  type: CHANGE_CURRENT_ALBUM,
  data: fromJS(data)
})

export const changeEnterLoading = data => ({
  type: CHANGE_ENTER_LOADING,
  data
})

export const getAlbumList = id => {
  return dispatch => {
    getAlbumDetailRequest(id)
      .then(res => {
        const data = res.playlist

        dispatch(changeCurrentAlbum(data))
        dispatch(changeEnterLoading(false))
      })
      .catch(() => {
        console.log('获取歌曲详情页失败')
      })
  }
}
